package com.egg.ylt.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import com.egg.ylt.R;
import com.egg.ylt.Utils.DateUtils;
import com.egg.ylt.pojo.IntegralFlowEntity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by sichaoqi on 2018/10/8.
 */

public class ADA_IntegralRecycler extends RecyclerView.Adapter<ADA_IntegralRecycler.IntegralViewHolder> {

    private Context mContext;
    private LayoutInflater mInflater;
    private List<IntegralFlowEntity.ListBean> mList;

    public ADA_IntegralRecycler(Context context) {
        this.mContext = context;
        mInflater = LayoutInflater.from(mContext);
        mList = new ArrayList<>();
    }

    public void setmList(List<IntegralFlowEntity.ListBean> list) {
        if (mList != null) {
            mList.clear();
        }
        mList.addAll(list);
        notifyDataSetChanged();
    }

    @Override
    public IntegralViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new IntegralViewHolder(mInflater.inflate(R.layout.item_transaction_recycler_view, parent, false));
    }

    @Override
    public void onBindViewHolder(IntegralViewHolder holder, int position) {
        IntegralFlowEntity.ListBean bean = mList.get(position);
        //时间
        holder.tvCreateTime.setText(bean.getCreateTime());
        //积分
        //根据交易类型显示
        switch (bean.getDealType()){
            case "0":
                holder.tvPrice.setText("+" + bean.getIntegral());
                break;
            case "1":
            case "2":
                holder.tvPrice.setText("-" + bean.getIntegral());
                break;
        }

    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    static class IntegralViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_create_time)
        TextView tvCreateTime;
        @BindView(R.id.tv_price)
        TextView tvPrice;
        public IntegralViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
